package com.twu.biblioteca;


public class Librarian {
    public Books allBook = new Books();
    public Movies allMovie = new Movies();
    public Users allUser = new Users();
    public boolean hasLogIn = false;
    public User currentUser;

    public int getBookNumbers() {
        return allBook.bookList.size();
    }
    public int getMoviesNumbers() {
        return allMovie.movieList.size();
    }

    public void listBooks() {
        System.out.println(allBook.showList());
    }

    public void listMovies() {
        System.out.println(allMovie.showList());
    }

    public boolean checkoutBook(String bookIndex) {
        String bookName = allBook.bookList.get(Integer.parseInt(bookIndex));
        if (allBook.bookTable.get(bookName).equals("")) {
            allBook.bookTable.put(bookName, currentUser.getName());
            return true;
        }
        else {
            return false;
        }
    }

    public boolean checkoutMovie(String movieIndex) {
        String movieName = allMovie.movieList.get(Integer.parseInt(movieIndex));
        if (allMovie.movieTable.get(movieName).equals("")) {
            allMovie.movieTable.put(movieName,currentUser.getName());
            return true;
        }
        else {
            return false;
        }
    }

    public boolean returnBook(String bookIndex) {
        String bookName = allBook.bookList.get(Integer.parseInt(bookIndex));
        if (allBook.bookTable.get(bookName).equals("")) {
            return false;
        } else {
            allBook.bookTable.put(bookName, "");
            return true;
        }
    }

    public boolean returnMovie(String movieIndex) {
        String movieName = allMovie.movieList.get(Integer.parseInt(movieIndex));
        if (allMovie.movieTable.get(movieName).equals("")) {
            return false;
        } else {
            allBook.bookTable.put(movieName, "");
            return true;
        }
    }

    public boolean login(String userID, String password) {
        if (allUser.userTable.containsKey(userID)) {
            if (allUser.userTable.get(userID).getPassword().equals(password)) {
                currentUser = allUser.userTable.get(userID);
                return true;
            }
            else
                return false;
        }
        else
            return false;
    }

}
